# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libpng

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.6.12
pkgrel=1
arch=('any')
pkgdesc="A collection of routines used to create PNG format graphics (mingw-w64)"
depends=("${MINGW_PACKAGE_PREFIX}-zlib" "${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
groups=("${MINGW_PACKAGE_PREFIX}")
license=('custom')
url="http://www.libpng.org/pub/png/libpng.html"
options=('strip' '!libtool' 'staticlibs')
source=("http://downloads.sourceforge.net/sourceforge/libpng/libpng-$pkgver.tar.xz"
        "http://downloads.sourceforge.net/project/libpng-apng/libpng16/$pkgver/libpng-$pkgver-apng.patch.gz")

md5sums=('ee752da8aa75076500e4cf31318e636e'
         'f959e8b1cb9876ce946a2701e8aca519')

prepare() {
  cd "$srcdir/libpng-$pkgver"

  # Add animated PNG (apng) support
  # see http://sourceforge.net/projects/libpng-apng/
  patch -p1 -i "${srcdir}/libpng-$pkgver-apng.patch"
}

build() {
  cd "$srcdir/libpng-$pkgver"

  mkdir -p "${srcdir}/build-${CARCH}"
  cd "${srcdir}/build-${CARCH}"
  ../libpng-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-shared --enable-static \
    as_ln_s="cp -pR"
  make
}

package () {
  cd "${srcdir}/build-${CARCH}"
  make install DESTDIR="${pkgdir}"
  
  install -D -m644 "${srcdir}/libpng-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname/LICENSE"
}
